<?php
class LoginWebUser extends CWebUser{
	public $register = false;
    public $detail ="";
    public $admin = null;
    public $test=null;
    public function afterLogin($fromCookie){
        $_SESSION['auto_login']=1;
        $login_log=new LoginLog();
        $login_log->customer_id=Yii::app()->user->id;
        $login_log->username=Yii::app()->user->name;
        $login_log->created=time();
        $login_log->ip=Yii::app()->tools->getIp();
        if(!empty($this->admin)){
            $login_log->type=3;//admin login
            $login_log->admin_id=$this->admin;
        }
        else if($this->register){
            $login_log->type=2;//register
        }
        else{
            $login_log->type=1;//login
        }
        if($this->test=='auto'){           
            $callback = $_GET['callback'];
            echo $callback.'('.json_encode(array('result'=>'success')).')';
            die;
        }
        $login_log->save();
    	if($this->register){
    		$this->register = false;
    		Yii::app()->getRequest()->redirect(Yii::app()->baseUrl."/myaccount/myavatar/".Yii::app()->user->id);
    	}
        if(!empty($this->detail)){
            Yii::app()->getRequest()->redirect($this->detail);       
        }
        Yii::app()->getRequest()->redirect(Yii::app()->params['site_url']);
    }
    
    
    public function afterLogout(){
        $_SESSION['auto_logout']=1;
        $_SESSION['is_admin']="";
        Yii::app()->getRequest()->redirect(Yii::app()->params['site_url']."?auto_logout=1");
    }
}